package cn.schoolwow.ams.test.config;

import cn.schoolwow.quickdao.QuickDAO;
import cn.schoolwow.quickdao.domain.DAO;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DAOConfig {
    @Bean(name = "starterDAO")
    public DAO starterDAO() {
        HikariDataSource hikariDataSource = getPostgresDataSource();
        QuickDAO quickDAO = QuickDAO.newInstance()
                .dataSource(hikariDataSource)
                .packageName("cn.schoolwow.ams.test.entity");
        DAO starterDAO = quickDAO.build();
        return starterDAO;
    }

    /**获取postgres数据源*/
    private HikariDataSource getPostgresDataSource(){
        HikariDataSource hikariDataSource = new HikariDataSource();
        hikariDataSource.setDriverClassName("org.postgresql.Driver");
        hikariDataSource.setJdbcUrl("jdbc:postgresql://127.0.0.1:5432/ams?stringtype=unspecified");
        hikariDataSource.setUsername("postgres");
        hikariDataSource.setPassword("123456");
        return hikariDataSource;
    }
}
